package com.xyc.study.stu_demo.service;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xyc.study.stu_demo.entity.UserEntity;
import com.xyc.study.stu_demo.mapper.UserMapper;
import com.xyc.study.stu_demo.po.StuUserPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {
    @Autowired
    private UserMapper userMapper;

    public List<StuUserPO> getUsers(UserEntity userEntity) {
        // 创建查询条件
        QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
        
        // 设置查询条件
        if (userEntity.getLoginName() != null) {
            queryWrapper.like("login_name", userEntity.getLoginName());
        }
        if (userEntity.getUserName() != null) {
            queryWrapper.like("user_name", userEntity.getUserName());
        }
        
        // 执行查询
        List<UserEntity> dbList = userMapper.selectList(queryWrapper);
        
        // 转换并返回结果
        return BeanUtil.copyToList(dbList, StuUserPO.class);
    }
}
